#ifndef __BLE_H
#define __BLE_H

#ifdef __cplusplus
#extern "C" {
#endif
    
#include "esp_bt.h"

#include "esp_gap_ble_api.h"
#include "esp_gatts_api.h"
#include "esp_bt_defs.h"
#include "esp_bt_main.h"
#include "esp_bt_device.h"
#include "esp_gatt_common_api.h"

#define PROFILE_NUM 3
#define IMU_PROFILE_APP_ID 0
// define a custom GATT service UUID
#define IMU_SVC_UUID 0x1900
#define IMU_NUM_HANDLE 4  // Service(1) + Char declaration(1) + Char value(1) + CCCD(1) = 4
#define MOTOR_PROFILE_APP_ID 1
#define MOTOR_SVC_APP_ID 1
#define MOTOR_SVC_UUID 0x1901
#define MOTOR_CHAR_UUID 0x2A56          // Digital Output (标准)
#define MOTOR_NUM_HANDLE 3              // Service + Char + Char Value = 3
#define ATOMIZER_PROFILE_APP_ID 2
#define ATOMIZER_SVC_APP_ID 2
#define ATOMIZER_SVC_UUID 0x1902
// #define ATOMIZER_CHAR_UUID 0x2A56       // Digital Output (标准)
#define ATOMIZER_NUM_HANDLE 3           // Service + Char + Char Value = 3

struct gatts_profile_inst {
    esp_gatts_cb_t gatts_cb;
    uint16_t gatts_if;
    uint16_t app_id;
    uint16_t conn_id;
    uint16_t service_handle;
    esp_gatt_srvc_id_t service_id;
    uint16_t char_handle;
    esp_bt_uuid_t char_uuid;
    esp_gatt_perm_t perm;
    esp_gatt_char_prop_t property;
    uint16_t descr_handle;
    esp_bt_uuid_t descr_uuid;
};
    
extern uint8_t imu_data_val[6];
extern uint8_t motor_status_val[1];
extern float motor_duty_rate_val;
extern uint8_t atomizer_status_val[1];
extern float atomizer_duty_rate_val;

extern struct gatts_profile_inst gl_profile_tab[PROFILE_NUM];

void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param);
void gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param);
esp_err_t ble_init(void);

#ifdef __cplusplus
}
#endif

#endif
